﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using KBEngine;

public class FieldList : MonoBehaviour
{
    Account account;
    public GameObject[] fieldbgArray;
    float serverTimer = 2.0f;

    void Start ()
    {
        account = (Account)KBEngineApp.app.player();
        this.InitFieldList(account.fieldList);
	}

    //初始化地块数据
    void InitFieldList(FIELD_LIST fieldList)
    {
        foreach (FIELD_INFO fieldInfo in fieldList)
        {
            GameObject field = (GameObject)Instantiate(Resources.Load("prefabs/field"));
            field.transform.SetParent(this.fieldbgArray[fieldInfo.index - 1].transform);
            field.transform.localPosition = Vector3.zero;
            GameObject crop = field.transform.Find("crop").gameObject;
            string spritePath = "crop/crop_" + fieldInfo.cropId + "_4";
            crop.GetComponent<Image>().overrideSprite = Resources.Load(spritePath, typeof(Sprite)) as Sprite;
        }
    }

    private void Update()
    {
        if (serverTimer > 0)
        {
            serverTimer -= Time.deltaTime;
        }
        if (serverTimer <= 0)
        {
            account.serverTime += 1;
        }
    }
}
